<?php

namespace App\DB\Steam;

use App\DB\CommonDB;
use App\Model\Steam\SteamGame;
use App\Model\Steam\SteamGameCollocation;
use App\Model\Steam\SteamGameGoods;
use App\Model\Steam\SteamGameTag;
use App\Model\Steam\SteamNews;
use Illuminate\Support\Facades\DB;

class SteamGameTagDB
{


    /**
     * 根据标签获取游戏列表
     *
     * @param $id
     * @return mixed
     */
      public static function getGameByTag($tageId)
      {
          $tag = SteamGameTag::find($tageId);
          if(!$tag) {
              return false;
          }
          # 查询游戏的全局标签
          $data = DB::table('steam_game_tag_map as map')->select('map.game_id', 'map.tag_id', 'game.title', 'game.thumb', 'game.price', 'game.is_discount', 'game.discount_price')
              ->leftJoin('steam_game as game', 'map.game_id', '=', 'game.id')->where('map.tag_id', $tageId)
              ->orderBy('game.issue_date')->skip(1)->take(9)->get();
          if($data) {
              $data = $data->toArray();
          }
          $respone = [
              'tag_id' =>  $tageId,
              'tag_title' =>  $tag->title,
              'data' =>  $data,
          ];
          return $respone;
      }
}
